﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.BLL.Extend;
using ZX.DAL.DBExtend;
using ZX.SYS.Library;

namespace ZX.SYS.Bussiness.DeskTop
{
    public class BSysDesktopTemplate : BaseBussnies
    {
        /// <summary>
        /// 获取所有 桌面模板表
        /// </summary>
        /// <returns></returns>
        public IList<SysDesktopTemplate> GetDeskTopTemplateList(string RoleID)
        {
            this.entity = new SysDesktopTemplate();
            this.GetEntitys<SysDesktopTemplate>("DeskTopTempID not in (select DeskTopTempID from SysRoleDesktop where RoleId='" + RoleID + "')");
            return this.GetEntitysBySqlComm<SysDesktopTemplate>("select * from SysDesktopTemplate where DeskTopTempID not in (select DeskTopTempID from SysRoleDesktop where RoleId='" + RoleID + "')");
        }

        /// <summary>
        /// 获取某个桌面模板
        /// </summary>
        /// <returns></returns>
        public SysDesktopTemplate GetSysDesktopTemplateEntity(string DeskTopTempID, string RoleID)
        {
            this.entity = new SysDesktopTemplate();
            string sql = @"
                    select 
                    a.DeskTopTempID
                    ,a.DeskTopTempName
                    ,a.Src
                    ,a.Height
                    ,a.EntityName
                    ,a.Parameter
                    ,a.Sort
                    ,a.PageType
                    ,MIN(Coalesce(b.PowerType,a.PowerType,0)) OVER (PARTITION  BY a.DeskTopTempID) AS PowerType
                    ,a.TabTools
                    ,a.Region
                    ,a.More
                     from SysDesktopTemplate a,SysRoleDesktop b where a.DeskTopTempID=b.DeskTopTempID 
                    and a.DeskTopTempID='@DeskTopTempID'  and b.RoleId='@RoleID'";
            sql = sql.Replace("@DeskTopTempID", DeskTopTempID);
            sql = sql.Replace("@RoleID", RoleID);
            return (SysDesktopTemplate)this.GetEntityBySqlComm(sql);
        }

        /// <summary>
        /// 获取某个桌面模板
        /// </summary>
        /// <returns></returns>
        public SysDesktopTemplate GetSysDesktopTemplateEntity2(string DeskTopTempID)
        {
            this.entity = new SysDesktopTemplate();
            string sql = @"select * from SysDesktopTemplate where DeskTopTempID='@DeskTopTempID'";
            sql = sql.Replace("@DeskTopTempID", DeskTopTempID);
            return (SysDesktopTemplate)this.GetEntityBySqlComm(sql);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="DeskTopTempID"></param>
        /// <returns></returns>
        public bool DeleteysDesktopTemplate(string DeskTopTempID)
        {
            this.entity = new SysDesktopTemplate();
            try
            {
                return this.delete(" DeskTopTempID = '" + DeskTopTempID + "'");
            }
            catch {
                return false;
            }
        }
    }
}
